package com.hxzy.projectssmplus.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hxzy.projectssmplus.dto.SysDicTypeDTO;
import com.hxzy.projectssmplus.entity.SysDictType;
import com.hxzy.projectssmplus.service.SysDictTypeService;
import com.hxzy.projectssmplus.vo.AjaxResult;
import com.hxzy.projectssmplus.vo.AjaxTableInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
public class DictController extends BaseController {
    @Autowired
    private SysDictTypeService sysDictTypeService;

    @GetMapping(value = "/dict/date")
    public AjaxTableInfo dictData(SysDicTypeDTO sysDicTypeDTO){
        //System.out.println("dict/date 获取的参数   "+sysDicTypeDTO.getMap());
        IPage iPage = super.startPage();
        IPage<SysDictType> sysDictTypeIPage = this.sysDictTypeService.searchByXML(iPage, sysDicTypeDTO);
        return getTableInfo(sysDictTypeIPage);
    }
    @GetMapping(value = "/dict/add")
    public AjaxResult dictAdd(SysDictType sysDictType){
        //System.out.println("dict/add获得的参数      "+sysDictType);
        Integer integer = this.sysDictTypeService.insertDict(sysDictType);
        return  integer>0?AjaxResult.success("dict/add插入数据成功"):AjaxResult.error("dict/add插入数据失败");
    }
    @GetMapping(value = "/dict/del")
    public AjaxResult dictDel(Long[] delIds){
//        System.out.println("dict/del获得的参数     "+ delIds);
        List<Long> longList = Arrays.asList(delIds);
        Integer integer = this.sysDictTypeService.delateDict(longList);
        return  integer>0 ?AjaxResult.success("dict/del删除数据成功"):AjaxResult.error("dict/del删除数据失败");
    }
    @GetMapping(value ="/dict/delone/{dictId}")
    public AjaxResult dictDelOne(@PathVariable(value = "dictId") Long dictId){
        //System.out.println("dedaocanshu  输出其中id "+sysDictType.getDictId());
        //System.out.println("dict.delone 获取的参数   "+id);
        int i = this.sysDictTypeService.delateOne(dictId);
        return i>0?AjaxResult.success("delone 删除成功"):AjaxResult.error("deloe删除失败");
    }
    @GetMapping(value = "/dict/update")
    public AjaxResult dictUpdate(SysDictType sysDictType){

        Integer integer = this.sysDictTypeService.dictUpdate(sysDictType);
        return  integer>0?AjaxResult.success("dict/update修改数据成功"):AjaxResult.error("dict/update修改数据失败");
    }



}
